<template>
  <div style="padding: 30px;">
    <div class="my_main">
      <el-form ref="articleRef" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="联系方式" prop="phoneNumber">
          <el-input v-model="form.phoneNumber" placeholder="请输入联系方式" />
        </el-form-item>
        <el-form-item label="邮箱" prop="email">
          <el-input v-model="form.email" placeholder="请输入邮箱" />
        </el-form-item>
        <editor v-model="form.content" :min-height="192"/>
      </el-form>
      <div style="padding: 30px 0; text-align: right;">
        <el-button style="width: 100px;" type="primary" @click="submitForm">保存</el-button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { getArticleByType, saveSingleTypeArticle } from '@/api/article/article'
const { proxy } = getCurrentInstance();
const form = ref({})
const rules = ref({
})
function getData() {
  getArticleByType('ABOUT_US').then(res => {
    if (res.data) {
      form.value = res.data[0]
    }
  })
}
function submitForm() {
  proxy.$refs["articleRef"].validate(valid => {
    if (valid) {
      form.value.name = '关于我们'
      form.value.type = 'ABOUT_US'
      saveSingleTypeArticle(form.value).then(response => {
          proxy.$modal.msgSuccess("保存成功")
          open.value = false
          getData()
      });
    }
  });
}
getData()
</script>